package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.uni.domain.DcTypes;
import com.ruoyi.uni.service.IDcTypesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点餐类型Controller
 * 
 * @author hx
 * @date 2024-04-14
 */
@RestController
@RequestMapping("/system/types")
public class DcTypesController extends BaseController
{
    @Autowired
    private IDcTypesService dcTypesService;

    /**
     * 查询点餐类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcTypes dcTypes)
    {
        startPage();
        List<DcTypes> list = dcTypesService.selectDcTypesList(dcTypes);
        return getDataTable(list);
    }

    /**
     * 导出点餐类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:types:export')")
    @Log(title = "点餐类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcTypes dcTypes)
    {
        List<DcTypes> list = dcTypesService.selectDcTypesList(dcTypes);
        ExcelUtil<DcTypes> util = new ExcelUtil<DcTypes>(DcTypes.class);
        util.exportExcel(response, list, "点餐类型数据");
    }

    /**
     * 获取点餐类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:types:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dcTypesService.selectDcTypesById(id));
    }

    /**
     * 新增点餐类型
     */
    @PreAuthorize("@ss.hasPermi('system:types:add')")
    @Log(title = "点餐类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcTypes dcTypes)
    {

        return toAjax(dcTypesService.insertDcTypes(dcTypes));
    }

    /**
     * 修改点餐类型
     */
    @PreAuthorize("@ss.hasPermi('system:types:edit')")
    @Log(title = "点餐类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcTypes dcTypes)
    {
        return toAjax(dcTypesService.updateDcTypes(dcTypes));
    }

    /**
     * 删除点餐类型
     */
    @PreAuthorize("@ss.hasPermi('system:types:remove')")
    @Log(title = "点餐类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dcTypesService.deleteDcTypesByIds(ids));
    }
    @PreAuthorize("@ss.hasPermi('system:types:edit')")
    @PostMapping("/move")
    public String moveUp(@RequestBody JSONObject js){

        return dcTypesService.move(js.getLong("id"),js.getInteger("flag"));
    }
}
